package com.liumuxian.exam.web.controller;

import com.liumuxian.exam.data.ExamInfoVO;
import com.liumuxian.exam.pojo.ExamInfo;
import com.liumuxian.exam.pojo.ExamInfo;
import com.liumuxian.exam.service.ExamInfoService;
import com.sun.org.apache.regexp.internal.RE;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/examinfo")
public class ExamInfoController {
    @Autowired
    private ExamInfoService examInfoService;
    @GetMapping("/view/{id}")
    public Result findExamQuestion(@PathVariable String id){
        ExamInfoVO examInfoVO =  examInfoService.findExamQuestion(id);
        return new Result(true, StatusCode.OK,"成功",examInfoVO);
    }
    @GetMapping("/page/{sid}/{eid}")
    public Result pageExam(@PathVariable String sid,@PathVariable String eid){
        List<ExamInfo> examInfo = examInfoService.findAllBySubjectassoetedidAndExamclassifyid(sid,eid);
        return new Result(true, StatusCode.OK,"成功",examInfo);
    }
    @PostMapping("/save")
    public Result save(@RequestBody ExamInfo examInfo){
        examInfoService.save(examInfo);
        return new Result(true, StatusCode.OK,"保存成功！");
    }
    @PostMapping("/update")
    public Result update(@RequestBody ExamInfo examInfo){
        examInfoService.update(examInfo);
        return new Result(true, StatusCode.OK,"修改成功！");
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable String id){
        examInfoService.delete(id);
        return new Result(true, StatusCode.OK,"删除成功！");
    }
    @GetMapping("/list")
    public Result findAllGesTate(){
        List<ExamInfo> examInfoList = examInfoService.findAllGesTate(null,null,0);
        return new Result(true, StatusCode.OK,"查询成功！",examInfoList);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable String id){
        ExamInfo examInfoList = examInfoService.findById(id);
        return new Result(true, StatusCode.OK,"查询成功！",examInfoList);
    }
}
